package com.hsxc.cdz.biz.reserve;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hsxc.cdz.base.bean.Reserv;
import com.hsxc.cdz.base.dao.ReservDao;

import java.util.List;

/**
 * @author 作者 : 陈钊
 * @version 创建时间：2016年8月20日 下午3:12:30 类说明： 该类主要操作数据库
 */
@Service("reservManager")
public class ReservManager {
	@Autowired
	private ReservDao reservDao;

	// ------------------数据库操作----------------------
	/**
	 * 创建预约记录
	 * 
	 * @param reserv
	 * @return
	 */
	public int insertReserv(Reserv reserv) {
		return reservDao.insertReserv(reserv);
	}

	/**
	 * 查询指定用户的预约记录
	 * 
	 * @param userNo
	 * @return
	 */
	public List<Reserv> selReserv(String userNo) {
		Reserv reserv =new Reserv();
		reserv.setUserNo(userNo);
		return reservDao.selectReserv(reserv);
	}
	public  Reserv selReservByNo(String reservNo){
		Reserv reserv =new Reserv();
		reserv.setResNo(reservNo);
		return reservDao.selReservByNo(reserv);
	}
	// 数据库预约记录不允许删除

	// public int deleteReserv(String reservNo) {
	// Reserv reserv = new Reserv();
	// reserv.setResNo(reservNo);
	// return reservDao.deleteResev(reserv);
	// }
	/**
	 * update reserv
	 * 
	 * @param reservNo
	 * @param startTime
	 * @param stopTime
	 * @param isCancelled
	 * @return
	 */
	public int updateReserv(String reservNo, String startTime, String stopTime, boolean isCancelled) {
		Reserv reserv = new Reserv();
		reserv.setResNo(reservNo);
		reserv.setCancelled(isCancelled);
		reserv.setReservStartTime(startTime);
		reserv.setReservStopTime(stopTime);
		return reservDao.updateReserv(reserv);
	}

	/**
	 * update reserv by whether is Cancelled
	 * 
	 * @param reservNo
	 * @param isCancelled
	 * @return
	 */
	public int updateReserv(String reservNo, boolean isCancelled,int state) {
		Reserv reserv = new Reserv();
		reserv.setResNo(reservNo);
		reserv.setCancelled(isCancelled);
		reserv.setState(state);
		return reservDao.updateReserv(reserv);
	}

}
